﻿using UnityEngine;
using System.Collections;

public class ChurchDestroy : MonoBehaviour {

	
	public int countCol= 0;
	public int hitpoints = 80;
	public Transform ExplosionPrefab;

	private bool victorious = false;
	private float victoryTimer = 3.0f;
	// Use this for initialization
	void Start () {
		victorious = false;
	}

	void Update(){
		if(victorious){
			victoryTimer -= Time.deltaTime;
		}
		if(victoryTimer < 0){
			Application.LoadLevel(3);
		}
	}

	void OnCollisionEnter (Collision col) {
		
		if(col.gameObject.tag.Equals("Shot") && !victorious){
			countCol++;
			col.gameObject.SendMessage("Kill");
			if(countCol >= hitpoints)
			{
				//transform.renderer.bounds.center um explosion in der mitte zu spawnen
				Kill();
			}
		}
	}

	public void Kill(){
		Instantiate(ExplosionPrefab, transform.renderer.bounds.center, Quaternion.identity);
//		Destroy(gameObject);
		victorious = true;
	}


	
}
